home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / prterr.zip / DRIVER.C < prev    next >
C/C++ Source or Header  |  1993-01-04  |  8KB  |  228 lines

  1. /***************************************************************************/
  2. /*                                                                         */
  3. /* driver.c - program to test the prttest() function                       */
  4. /*                                                                         */
  5. /* Command line syntax:  DRIVER [1|2 d]                                    */
  6. /*                                                                         */
  7. /*        where:  1|2 is the printer port (1=LPT1)                         */
  8. /*                      if none specified, default is LPT1                 */
  9. /*                                                                         */
  10. /*                d   enables "debug" mode - printer port status is        */
  11. /*                      displayed to the screen on errors                  */
  12. /*                                                                         */
  13. /*                                                                         */
  14. /*       Examples:  DRIVER 1 d - print to LPT1, debug active               */
  15. /*                  DRIVER     - print to LPT1, debug not active           */
  16. /*                  DRIVER 2   - print to LPT2, debug not active           */
  17. /*                                                                         */
  18. /***************************************************************************/
  19.  
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <conio.h>                  /* for clrscr()                        */
  23. #include <ctype.h>                  /* for toupper()                       */
  24. #include <bios.h>                   /* for bioskey() - see gethex()        */
  25.  
  26. int port = 0;                       /* Printer port used - Default LPT1    */
  27. int ptrstat;                        /* Status of line printer port         */
  28. int saveptrstat;                    /* Saved version for debug mode        */
  29.  
  30. unsigned char debug;                /* Used to trace printer problems      */
  31. unsigned char digit;
  32.  
  33. int prttest(int port);              /* Function declaration                */
  34.  
  35. void main(char argc,char **argv)
  36.     {
  37. /*9 comment: ****************************************************************
  38.  *9 Handle the command line parms, if any.
  39.  ****************************************************************************/
  40.  
  41.     if ( argc > 1 )
  42.         {
  43.         if ( ((char)*argv[1] == '1') || ((char)*argv[1] == '2') )
  44.             {
  45.             port = (atoi(argv[1]))-1;
  46.             }
  47.         else
  48.             {
  49.             printf("\n\nImproper LPT port designation!\n\n");
  50.             printf("Invocation:  %s [1|2 d] \n",argv[0]);
  51.             printf("    where 1=LPT1, 2=LPT2\n");
  52.             printf("          d - enables debug mode\n");
  53.             exit(2);
  54.             }
  55.         if ( argc == 3 )
  56.             {
  57.             debug = *argv[2];
  58.             }
  59.         }
  60.  
  61.  
  62. /*9 comment: ****************************************************************
  63.  *9 Test the printer port to see if it's ready.
  64.  ****************************************************************************/
  65.  
  66.     while (  (ptrstat = (prttest(port))) != 0 )
  67.         {
  68.         clrscr();
  69.         printf("\n\n\n\n\n\n\n\n\n\n");
  70.         switch(ptrstat)
  71.             {
  72.             case 1:
  73.                 {
  74.                 printf("          Printer is off line!  ");
  75.                 break;
  76.                 }
  77.             case 2:
  78.                 {
  79.                 printf("          Printer is out of paper!  ");
  80.                 break;
  81.                 }
  82.             case 3:
  83.                 {
  84.                 printf("          Printer is powered off!  ");
  85.                 break;
  86.                 }
  87.             case 4:
  88.                 {
  89.                 printf("          Printer is not attached!  ");
  90.                 break;
  91.                 }
  92.             case 5:
  93.                 {
  94.                 printf("    Printer port is invalid!  ");
  95.                 printf("Try again with a valid port specification.\n");
  96.                 if ( toupper(debug) == 'D' )
  97.                     {
  98.                     printf("    (ptrstat = %02X)\n",saveptrstat);
  99.                     }
  100.                 exit(2);
  101.                 }
  102.             case 6:
  103.                 {
  104.                 printf("          Unknown printer problem!  ");
  105.                 break;
  106.                 }
  107.             }
  108.  
  109.         printf("Correct and press a key...");
  110.  
  111.  
  112. /*9 comment: ****************************************************************
  113.  *9 If "debug" mode is active, display the printer port's status
  114.  ****************************************************************************/
  115.         
  116.         if ( toupper(debug) == 'D' )
  117.             {
  118.               printf(" (ptrstat = %02X)",saveptrstat);
  119.             }
  120.  
  121.         while ( kbhit() )
  122.             {
  123.             getch();
  124.             }
  125.         digit = getch();
  126.         }
  127.  
  128. /*9 comment: ****************************************************************
  129.  *9 Print the message
  130.  ****************************************************************************/
  131.  
  132.     fprintf(stdprn,"This is a test message.\r\n");
  133.     }
  134.  
  135. /***************************** D I E B O L D ********************************
  136.  *
  137.  *1  FUNCTION:  prttest
  138.  *
  139.  *2  SUMMARY:  This function tests the printer port to see if it is ready
  140.  *
  141.  *3  INVOCATION: int prttest(int port)
  142.  *
  143.  *4  INPUTS:  Port to be tested (0 = LPT1:, 1 = LPT2:)
  144.  *
  145.  *5  OUTPUTS: Returns 0 if printer is ready.
  146.  *5                   1 if printer is off-line
  147.  *5                   2 if printer is out of paper
  148.  *5                   3 if printer is powered off
  149.  *5                   4 if no printer is attached
  150.  *5                   5 if printer port is unavailable
  151.  *5                   6 if printer status is not recognized
  152.  *
  153.  *6  CAVEATS:
  154.  *
  155.  *7  AUTHOR: Brad Stephenson     DATE:  04/07/90
  156.  *            
  157.  *8  REVISION:  05/18/90 BSTE - Replaced int86() call with biosprint().
  158.  *8             05/29/90 BSTE - Added "debug" mode
  159.  *8                             Added ability to check LPT2
  160.  *
  161.  ****************************************************************************/
  162.  
  163. int prttest(int port)
  164.     {
  165.  
  166.     int ptrstatval;
  167.  
  168. /*9 comment: ****************************************************************
  169.  *9 Check Int 17 return for specific known problem returns
  170.  ****************************************************************************/
  171.     
  172.     ptrstatval = biosprint( 2, 0x00, port );
  173.  
  174. /*9 comment: ****************************************************************
  175.  *9 If we are in debug mode, save the returned value.
  176.  ****************************************************************************/
  177.  
  178.     if ( toupper(debug) == 'D' )
  179.         {
  180.         saveptrstat = ptrstatval;
  181.         }
  182.  
  183.  
  184. /*9 comment: ****************************************************************
  185.  *9 Based on the port status, return an appropriate value to the caller
  186.  ****************************************************************************/
  187.     
  188.     switch(ptrstatval)
  189.         {
  190.         case 0x90:
  191.             {
  192.             return(0);      /* Printer ready and on-line */
  193.             }
  194.         case 0x18:
  195.         case 0x08:
  196.             {
  197.             return(1);      /* Printer off-line          */
  198.             }
  199.         case 0x28:
  200.         case 0x38:
  201.             {
  202.             return(2);      /* Printer out of paper      */
  203.             }
  204.         case 0x48:
  205.         case 0xC8:
  206.             {
  207.             return(3);      /* Printer powered off       */
  208.             }
  209.         case 0x30:
  210.         case 0xB8:
  211.         case 0xB0:
  212.             {
  213.             return(4);      /* No printer attached       */
  214.             }
  215.         case 0x10:
  216.         case 0x4A:
  217.         case 0x02:
  218.             {
  219.             return(5);      /* Port selected is invalid  */
  220.             }
  221.         default:
  222.             {
  223.             return(6);      /* Unknown printer status    */
  224.             }
  225.         }
  226.     } /* End of prttest()  */
  227.  
  228.